aboutsummaryrefslogtreecommitdiffstats
path: root/src/routes/(app)/send/lightning/[payreq]/+page.server.js
blob: 9423137662d64e90d8aa82027f86814949265071 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { fail, redirect } from '@sveltejs/kit';
import { fd, auth, post } from '$lib/utils';

export async function load({ params }) {
	return post('/parse', params);
}

export const actions = {
	setAmount: async ({ cookies, request }) => fd(request),

	send: async ({ cookies, request }) => {
		try {
			let body = await fd(request);
			let { amount } = body;

			await post('/payments', body, auth(cookies));
		} catch (e) {
			if (e.message.includes('unusable'))
				e.message = 'Failed to route payment, try sending a lower amount';
			return fail(400, { message: e.message });
		}

		throw redirect(307, '/sent');
	}
};